package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.MqSetIpAndPort;

public class SetTemporaryControlSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqSetIpAndPort mqSetIpAndPort = (MqSetIpAndPort)mqMessage.getObject();
        String imei = mqSetIpAndPort.getImei();
        String commandNumber = mqSetIpAndPort.getCommandNumber();
        String ip = mqSetIpAndPort.getIpAddress();
        Integer port = mqSetIpAndPort.getPort();
        Integer retryTimes = mqSetIpAndPort.getRetryTimes();
        String content = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(mqMessage.getType()).concat(",")
                .concat(commandNumber).concat(",").concat(ip.replace(".",",")).concat(",").concat(String.valueOf(port)).concat(",").
                        concat(String.valueOf(retryTimes)).concat("#");
        Command command = new Command();
        command.setImei(imei);
        command.setCommandNumber(commandNumber);
        command.setCmd(mqMessage.getType());
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setContent(content);
        return command;
    }
}
